package com.htrq.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.htrq.entity.ICBasInfo;
import com.htrq.entity.Page;
import com.htrq.service.ICardService;
import com.htrq.util.ExportToExcelUtil;

@Controller
@RequestMapping("jsp/basinfo")
public class ICardController {
	@Resource
	private ICardService icService;
	
	@RequestMapping("getAllCard")
	@ResponseBody
	public String getAllCard(ICBasInfo info,Page page,HttpServletResponse response) throws IOException, ParseException{
		List<ICBasInfo> list=icService.getAllCard(info,page);
		String str = JSON.toJSONString(list);
		Long count = icService.getTotal(info);
		String json = "{total:" + count + ",icards:" + str + "}";
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(json);
		return null;
	}
	/**
	 *导出excel报表 
	 */
	@RequestMapping("exportexcel")
	public String export(ICBasInfo info,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String titles[]={"卡号","持卡人","卡类型","客户单位","车辆类型","车号","发卡站点","发卡人","状态","办卡时间"};
		List<Object[]> list=icService.exportbyForm(info);
		ExportToExcelUtil.exportToExcel(request,response,"刚查询导出的结果.xls", "卡数据", titles, list);
		return null;
	}
}
